package com.wj.crm.controller;

import com.wj.crm.base.BaseController;
import com.wj.crm.base.ResultInfo;
import com.wj.crm.enums.StateStatus;
import com.wj.crm.query.CusDevPlanQuery;
import com.wj.crm.query.SaleChanceQuery;
import com.wj.crm.service.CusDevPlanService;
import com.wj.crm.service.SaleChanceService;
import com.wj.crm.utils.LoginUserUtil;
import com.wj.crm.vo.CusDevPlan;
import com.wj.crm.vo.SaleChance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author WangJin
 * @version 1.0
 * @date 2021/12/20 19:04
 */

@RequestMapping("cus_dev_plan")
@Controller
public class CusDevPlanController extends BaseController {

    @Autowired
    private SaleChanceService saleChance;

    @Autowired
    private CusDevPlanService cusDevPlanService;
    /**
     * 客户开发主页面
     * @return
     */
    @RequestMapping("index")
    public String index() {
        return "cusDevPlan/cus_dev_plan";
    }

    /**
     * 客户开发计划详情页面
     */
    @RequestMapping("toCusDevPlanPage")
    public String toCusDevPlanPage(Integer id, HttpServletRequest request){
        SaleChance saleChance = this.saleChance.selectByPrimaryKey(id);
        request.setAttribute("saleChance",saleChance);
        return "cusDevPlan/cus_dev_plan_data";
    }

    /**
     * 多条件分页查询营销机会
     * @param query
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> queryCusDevPlanByParams (CusDevPlanQuery query , HttpServletRequest request) {

        return cusDevPlanService.queryCusDevPlanByParams(query);
    }

    /***
     * 计划项添加
     * @param cusDevPlan
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.addCusDevPlan(cusDevPlan);
        return success("计划项添加成功!");
    }

    @RequestMapping("addOrUpdateCusDevPlanPage")
    public String addOrUpdateCusDevPlanPage(Model model,Integer id,Integer saleChanceId){

        model.addAttribute("cusDevPlan",cusDevPlanService.selectByPrimaryKey(id));
        model.addAttribute("saleChanceId",saleChanceId);
        return "cusDevPlan/add_update";
    }

    /***
     * 计划项添加
     * @param cusDevPlan
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.updateCusDevPlan(cusDevPlan);
        return success("计划项更新成功!");
    }

    /**
     * 删除计划项
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public ResultInfo deleteCusDevPlan(Integer id){
        cusDevPlanService.delCusDevPlan(id);
        return success("计划项删除成功!");
    }


}
